﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI;

namespace MyModeler
{
    public class CFactory
    {
        public static CElement CreateElementOfType(ElementType type, ShapeType shape)
        {
	        CElement pNewElement = new CElement();
	        pNewElement.m_type = type;
	        pNewElement.m_shapeType = shape;
	        // Inc counter of created objects
	        g_counter++;
	        // element name
            DateTime dt = DateTime.Now;
	        pNewElement.m_name = String.Format("Element n°{0}", g_counter);
	
	        if( pNewElement.m_type == ElementType.type_shapes_simple )
	        {
		        switch( pNewElement.m_shapeType )
		        {
			        case ShapeType.line:
			        case ShapeType.line_right:
			        case ShapeType.rectangle:
			        case ShapeType.ellipse:
			        case ShapeType.rectangle_round:
			        case ShapeType.triangle:
			        case ShapeType.line_broken:
			        case ShapeType.line_broken_right:
			        case ShapeType.notimp_igloo:
			        case ShapeType.notimpl_multi_line:
			        case ShapeType.arrow_right:
			        case ShapeType.arrow_down:
			        case ShapeType.line2:
			        case ShapeType.line_right2:
			        case ShapeType.line_left_right:
			        case ShapeType.parenthese_gauche:
			        case ShapeType.parenthese_droite:
			        case ShapeType.etoile:
				        break;
			        default:
				        // Not implemented yet !
				        pNewElement.m_type = ElementType.type_unknown;
				        break;
		        }
	        }
	
	        if( pNewElement.m_type == ElementType.type_image )
	        {
		        switch( pNewElement.m_shapeType )
		        {
			        case ShapeType.image_fixed:
			        case ShapeType.image_scaled:
				        break;
			        default:
				        // Not implemented yet !
				        pNewElement.m_type = ElementType.type_unknown;
				        break;
		        }
	        }

	        if( pNewElement.m_type == ElementType.type_shapes_infrastructure )
	        {
		        // No line around the object
		        pNewElement.m_bColorLine = false;
		
		        switch( pNewElement.m_shapeType )
		        {
			        case ShapeType.infrastructure_server_ad:
				        pNewElement.m_image = "ServerAD.png";
				        break;
			        case ShapeType.infrastructure_server:
				        pNewElement.m_image = "Server.png";
				        break;
			        case ShapeType.infrastructure_server_web:
				        pNewElement.m_image = "ServerWeb.png";
				        break;
			        case ShapeType.infrastructure_server_database:
				        pNewElement.m_image = "ServerDatabase.png";
				        break;
			        case ShapeType.infrastructure_workstation:
				        pNewElement.m_image = "Workstation.png";
				        break;
			        case ShapeType.infrastructure_laptop:
				        pNewElement.m_image = "Laptop.png";
				        break;
			        case ShapeType.infrastructure_firewall:
				        pNewElement.m_image = "Firewall.png";
				        break;
			        case ShapeType.infrastructure_network:
				        pNewElement.m_image = "network.png";
				        break;
			        case ShapeType.infrastructure_virtual_server:
				        pNewElement.m_image = "Server_VM.png";
				        break;
			        case ShapeType.infrastructure_virtual_server_web:
				        pNewElement.m_image = "ServerWeb_VM.png";
				        break;
			        case ShapeType.infrastructure_virtual_server_database:
				        pNewElement.m_image = "ServerDatabase_VM.png";
				        break;
			        case ShapeType.infrastructure_virtualization_server:
				        pNewElement.m_image = "Virtualization_Server.png";
				        break;
			        case ShapeType.infrastructure_server_ad_grey:
				        pNewElement.m_image = "ServerAD_grey.png";
				        break;
			        case ShapeType.infrastructure_server_grey:
				        pNewElement.m_image = "Server_grey.png";
				        break;
			        case ShapeType.infrastructure_server_database_grey:
				        pNewElement.m_image = "ServerDatabase_grey.png";
				        break;
			        case ShapeType.infrastructure_server_farm:
				        pNewElement.m_image = "Server_Farm.png";
				        break;
			        case ShapeType.infrastructure_workstation_grey:
				        pNewElement.m_image = "Workstation_grey.png";
				        break;
			        case ShapeType.infrastructure_laptop_grey:
				        pNewElement.m_image = "Laptop_grey.png";
				        break;
			        default:
				        // Not implemented yet !
				        pNewElement.m_type = ElementType.type_unknown;
				        break;
		        }
	        }

	        if( pNewElement.m_type == ElementType.type_shapes_development )
	        {
		        pNewElement.m_bColorLine = true;
		        pNewElement.m_bColorFill = true;
		        pNewElement.m_bSolidColorFill = true;

		        // Set colors for development shapes
		        Color colorLineClass = Color.FromArgb(255, 52, 101, 164);
		        Color colorFillClass = Color.FromArgb(255, 200, 210, 233);
		        Color colorLineInterface = Color.FromArgb(255, 176, 167, 129);
		        Color colorFillInterface = Color.FromArgb(255, 217, 230, 203);
		        Color colorLineEnumeration = Color.FromArgb(255, 112, 88, 41);
		        Color colorFillEnumeration = Color.FromArgb(255, 175, 165, 120);
		        Color colorLinePackage = Color.FromArgb(255, 191, 161, 132);
		        Color colorFillPackage = Color.FromArgb(255, 255, 251, 240);
		        Color colorLineComment = Color.FromArgb(255, 202, 178, 45);
		        Color colorFillComment = Color.FromArgb(255, 251, 247, 200);
		        Color colorLineComponent = Color.FromArgb(255, 83, 134, 191);
		        Color colorFillComponent = Color.FromArgb(255, 181, 210, 237);

		        switch( pNewElement.m_shapeType )
		        {
			        case ShapeType.development_class:
				        pNewElement.m_text = "Class";
				        pNewElement.m_colorFill = colorFillClass;
				        pNewElement.m_colorLine = colorLineClass;
				        break;
			        case ShapeType.development_interface:
				        pNewElement.m_text = "Interface";
				        pNewElement.m_colorFill = colorFillInterface;
				        pNewElement.m_colorLine = colorLineInterface;
				        break;
			        case ShapeType.development_enumeration:
				        pNewElement.m_text = "Enumeration";
				        pNewElement.m_colorFill = colorFillEnumeration;
				        pNewElement.m_colorLine = colorLineEnumeration;
				        break;
			        case ShapeType.development_package:
				        pNewElement.m_text = "Package";
				        pNewElement.m_colorFill = colorFillPackage;
				        pNewElement.m_colorLine = colorLinePackage;
				        break;
			        case ShapeType.development_comment:
				        pNewElement.m_text = "Comment";
				        pNewElement.m_colorFill = colorFillComment;
				        pNewElement.m_colorLine = colorLineComment;
				        break;
			        case ShapeType.development_component:
				        pNewElement.m_text = "Component";
				        pNewElement.m_colorFill = colorFillComponent;
				        pNewElement.m_colorLine = colorLineComponent;
				        break;
			        case ShapeType.development_association:
			        case ShapeType.development_aggregation:
			        case ShapeType.development_composition:
			        case ShapeType.development_dependency:
			        case ShapeType.development_inheritance:
			        case ShapeType.development_package_import:
			        case ShapeType.development_connector:
				        break;
		        }
	        }
	
	        if( pNewElement.m_type == ElementType.type_text )
	        {
		        pNewElement.m_bColorLine = true;
		        pNewElement.m_bColorFill = false;
		        pNewElement.m_bSolidColorFill = true;
		        pNewElement.m_text = "<type text>";
	        }

	        if( pNewElement.m_type == ElementType.type_image )
	        {
		        // No line around the object
		        pNewElement.m_bColorLine = false;
	        }
	
	        return pNewElement;
        }


        // counter of objects
        static int g_counter = 0;
    }
}
